// -*- c++ -*-
/**************************************************************/
/*  This file is licensed from, and is a trade secret of:     */
/*                                                            */
/*    Mercury Computer Systems, Incorporated                  */
/*    199 Riverneck Road                                      */
/*    Chelmsford, Massachusetts 01824-2820                    */
/*    United States of America                                */
/*    Telephone + 1 978 256-1300                              */
/*                                                            */
/*  Refer to your Software License Agreement for provisions   */
/*  on use, duplication, or disclosure.                       */
/*  US. Government users and prime contractors are also       */
/*  governed by the following Data Rights Notice:             */
/*  Use, duplication or disclosure by the US. Government is   */
/*  subject to the provisions set forth in FAR 52.227-14 for  */
/*  restricted rights or other agency data rights provisions  */
/*  on commercial software and documentation, as applicable.  */
/*                                                            */
/*  This file: (a) was developed at private expense, and no   */
/*  part was developed with government funds, (b) is a        */
/*  trade secret of Mercury Computer Systems, Inc. for the    */
/*  purposes of the Freedom of Information Act, (c) is        */
/*  "commercial computer software" subject to limited         */
/*  utilization as provided in the above noted Software       */
/*  License Agreement and (d) is in all respects data         */
/*  belonging exclusively to Mercury Computer Systems, Inc..  */
/*                                                            */
/**************************************************************/

/******************************************************************/
/* Copyright ¿ 1999-2003, Mercury Computer Systems, Inc.,         */
/* Chelmsford MA.,and all third party embedded software sources.  */
/* All rights reserved under the Copyright laws of US. and        */
/* international treaties.                                        */
/*                                                                */
/* Patent Pending                                                 */
/******************************************************************/


//$COPYRIGHT_END

#ifndef RF_H__
#define RF_H__

#include <iostream>
#include <string>
#include <math.h>
#include "CF__Resource_impl.h"
#include "AudioPort_impl.h"
#include "SceOsThreadManager.h"
#include "mc_error.h"

#ifndef PI
#define PI 3.14159265358979
#endif

#ifdef _WIN32
#pragma warning( disable : 4275 )
#pragma warning( disable : 4251 )
#endif


#ifdef _WIN32
#ifdef RF_EXPORTS
#define RF_EXPORT __declspec(dllexport)
#else
#define RF_EXPORT __declspec(dllimport)
#endif
#else
#define RF_EXPORT 
#endif

class RF_EXPORT RfChannelEmulator : public CF__Resource_impl {
public: 
  static status
  Create (RfChannelEmulator *& ModulatorHandle,
	  const char * identifier);

  // From CF::Resource
  void start ()
    throw (CORBA::SystemException, CF::Resource::StartError);
  void stop ()
    throw (CORBA::SystemException, CF::Resource::StopError);

  // From CF::PortSupplier
  CORBA::Object_ptr getPort (const CORBA::Char * name)
    throw (CORBA::SystemException, CF::PortSupplier::UnknownPort);

private:
  RfChannelEmulator (const char * identifier);
  ~RfChannelEmulator ();

  // Separate thread master function	
  static void RunWorker (void * param);
  // Inner loop function that deals with external commands
  void RunLoop ();
  // Inner loop method that performs component business logic
  virtual status Run ();

  status Init ();

  void ComplexAWGN (CMPLX_INT16 * rf_in,
		    CMPLX_INT16 * rf_out,
		    unsigned int num_samples);
  void ComplexAWUN (CMPLX_INT16 * rf_in,
		    CMPLX_INT16 * rf_out,
		    unsigned int num_samples);

  CMPLX_INT16 * m_input;    // input data buffer
  int m_input_count;  // number of samples currently in the buffer
  int m_samples_read; // number of samples read from the buffer

  SCE::OS::ThreadManager m_thread;
  CMPLX_INT16 * m_output;

  ComplexShortInPort_impl * m_rfcomplexin;
  ComplexShortOutPort_impl * m_rfcomplexout;

  bool m_threadrunning;
  bool m_bStop;

  float m_sigma; // standard deviation
};

#endif
